VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{41494E01-7FE8-11D3-9792-00C0A835B79B}#1.2#0"; "RFSCntl.ocx"
Begin VB.MDIForm MDIForm1 
   BackColor       =   &H8000000C&
   Caption         =   "RF SDK Shell Application MDIForm1"
   ClientHeight    =   5940
   ClientLeft      =   165
   ClientTop       =   855
   ClientWidth     =   5805
   Icon            =   "MDIForm1.frx":0000
   LinkTopic       =   "MDIForm1"
   StartUpPosition =   3  'Windows Default
   Begin RFSControllerControl.RFSController RFSController1 
      Left            =   2400
      Top             =   4320
      _ExtentX        =   1296
      _ExtentY        =   873
      ControllerPort  =   3000
   End
   Begin VB.PictureBox RFSController4 
      Align           =   1  'Align Top
      Height          =   480
      Left            =   0
      ScaleHeight     =   420
      ScaleWidth      =   5745
      TabIndex        =   1
      Top             =   0
      Width           =   5805
   End
   Begin MSComctlLib.StatusBar StatusBar1 
      Align           =   2  'Align Bottom
      Height          =   315
      Left            =   0
      TabIndex        =   0
      Top             =   5625
      Width           =   5805
      _ExtentX        =   10239
      _ExtentY        =   556
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   1
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
      EndProperty
   End
   Begin VB.Menu mnuOptions 
      Caption         =   "&Options"
   End
   Begin VB.Menu mnuViewLog 
      Caption         =   "&View Log"
   End
   Begin VB.Menu mnuWindow 
      Caption         =   "&Window"
      Begin VB.Menu mnuWindowNewWindow 
         Caption         =   "&New Window"
      End
      Begin VB.Menu mnuWindowBar0 
         Caption         =   "-"
      End
      Begin VB.Menu mnuWindowCascade 
         Caption         =   "&Cascade"
      End
      Begin VB.Menu mnuWindowTile 
         Caption         =   "&Tile &Horizontal"
      End
      Begin VB.Menu mnuWindowArrangeIcons 
         Caption         =   "&Arrange Icons"
      End
      Begin VB.Menu mnuWindowSep1 
         Caption         =   "-"
      End
      Begin VB.Menu mnuWindowShowAll 
         Caption         =   "&Show All"
      End
      Begin VB.Menu mnuWindowHideAll 
         Caption         =   "Hi&de All"
      End
   End
   Begin VB.Menu mnuTrayIconMenu 
      Caption         =   "TrayIconMenu"
      Visible         =   0   'False
      Begin VB.Menu mnuTIRestore 
         Caption         =   "&Restore"
      End
      Begin VB.Menu mnuTIOptions 
         Caption         =   "&Options"
      End
      Begin VB.Menu mnuTIClose 
         Caption         =   "&Close"
      End
      Begin VB.Menu mnuSep 
         Caption         =   "-"
      End
      Begin VB.Menu mnuTIAbout 
         Caption         =   "&About"
      End
   End
End
Attribute VB_Name = "MDIForm1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public clsTI As clsTrayIcon
Public SessionNumber As Integer
Public blnShowAll As Boolean  'persists state of child windows

Public ws1 As Integer  'persists arrangement of child windows

Public WithEvents dc As RF_App.MDBData
Attribute dc.VB_VarHelpID = -1
'Public WithEvents dc As RF_App.MDBData

Private Sub dc_ConError(Number As Long, Source As String, Description As String)
    'Err.Raise Number, Source, Description
End Sub

Private Sub dc_ConEvent(Number As Long, Description As String, ConName As String)
    Err.Raise Number, ConName, Description
End Sub

Private Sub MDIForm_Load()
SessionNumber = 1
RFSController1.ListenForConnectionRequest
Set clsTI = New clsTrayIcon


clsTI.InitTrayIcon MDIForm1, "RFApp v" & App.Major & "." & App.Minor & "." & App.Revision & IIf(GetCmdParameter("/N:") = "", "", " DEBUGGING MODE")
Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000)
Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000)
Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 6500)
Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6500)
ws1 = GetSetting(App.Title, "Settings", "WS", 0)
blnShowAll = GetSetting(App.Title, "Settings", "ShowAll", False)

If Me.Left < 1 Then Me.Left = 1
If Me.Top < 1 Then Me.Top = 1

Select Case ws1
    Case 0  'minimized
        mnuWindowHideAll_Click
    Case 1  'cascade
        mnuWindowCascade_Click
    Case 2  'tile
        mnuWindowTile_Click
    Case Else
        
End Select

If Not blnShowAll Then Me.Hide
StatusBar1.Panels(1).Text = ""
StatusBar1.Panels(1).AutoSize = sbrContents
End Sub

Private Sub MDIForm_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    clsTI.Mdl_MouseMove Button, Shift, X, Y, Me
End Sub

Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Dim str1 As String
    str1 = GetCmdParameter("/N:")
    If str1 = "" And gintExiting = 0 Then
        If MsgBox(GetMessage("msgShutDown"), vbYesNo, Me.Caption) = vbNo Then
            Cancel = 1
        End If
    End If
End Sub

Private Sub MDIForm_Resize()
    Static blnVisible As Boolean
    If Me.WindowState = vbMinimized And blnVisible Then
        Me.Visible = False
        blnVisible = False
    Else
        blnVisible = True
        Me.Visible = True
        Me.WindowState = vbNormal
    End If
End Sub

Private Sub MDIForm_Unload(Cancel As Integer)
    Me.RFSController1.ControllerClose
    clsTI.DeleteTrayIcon
    If Me.WindowState <> vbMinimized Then
        SaveSetting App.Title, "Settings", "MainLeft", Me.Left
        SaveSetting App.Title, "Settings", "MainTop", Me.Top
        SaveSetting App.Title, "Settings", "MainWidth", Me.Width
        SaveSetting App.Title, "Settings", "MainHeight", Me.Height
    End If
    SaveSetting App.Title, "Settings", "ShowAll", blnShowAll
    SaveSetting App.Title, "Settings", "WS", ws1
    
    If Not rsUsers Is Nothing Then
        If rsUsers.State <> 0 Then rsUsers.Close
        Set rsUsers = Nothing
    End If
    If Not rsRFLabel Is Nothing Then
        If rsRFLabel.State <> 0 Then rsRFLabel.Close
        Set rsRFLabel = Nothing
    End If
    If Not rsRFMessage Is Nothing Then
        If rsRFMessage.State <> 0 Then rsRFMessage.Close
        Set rsRFMessage = Nothing
    End If
    If Not rsRFSystemParameter Is Nothing Then
        If rsRFSystemParameter.State <> 0 Then rsRFSystemParameter.Close
        Set rsRFSystemParameter = Nothing
    End If
    If Not rsSystemParameters Is Nothing Then
        If rsSystemParameters.State <> 0 Then rsSystemParameters.Close
        Set rsSystemParameters = Nothing
    End If

    dc.CloseConnections wcAll
    CloseLocalConnection

    Unload Me
End Sub

Private Sub mnuOptions_Click()
    mnuTIOptions_Click
End Sub

Private Sub mnuTIAbout_Click()
    Dim frmAbt As New frmAbout
    frmAbt.Show vbModal
End Sub

Private Sub mnuTIOptions_Click()
    Dim frmOpt As New frmOptions
    frmOpt.Show vbModal
End Sub

Private Sub mnuTIClose_Click()
    Unload Me
End Sub

Private Sub mnuTIRestore_Click()
    Me.WindowState = vbNormal
    Me.Visible = True
End Sub

Private Sub mnuViewLog_Click()
    On Error Resume Next
    If Shell("notepad.exe " & App.Path & "\error.log", vbNormalFocus) = 0 Then
        MsgBox GetMessage("msgNoErrors")
    End If
    If Err.Number <> 0 Then Err.Clear
    
End Sub

Private Sub mnuWindowArrangeIcons_Click()
    Me.Arrange vbArrangeIcons
End Sub

Private Sub mnuWindowCascade_Click()
    mnuWindowShowAll_Click
    Me.Arrange vbCascade
    ws1 = 1
End Sub

Private Sub mnuWindowNewWindow_Click()
    Dim i As Integer
    For i = 1 To MAX_SESSIONS
        If AppForm(i).Tag <> "Loaded" Then
            AppForm(i).Show
            Exit For
        End If
    Next i
End Sub

Private Sub mnuWindowShowAll_Click()
    Dim i As Integer
    For i = 1 To MAX_SESSIONS
        AppForm(i).WindowState = vbNormal
    Next i
    Me.Arrange vbCascade
    ws1 = 1
    blnShowAll = True
End Sub
Private Sub mnuWindowHideAll_Click()
Dim i As Integer
    For i = 1 To MAX_SESSIONS
        AppForm(i).WindowState = vbMinimized
    Next i
    Me.Arrange vbArrangeIcons
    blnShowAll = False
    ws1 = 0
End Sub

Private Sub mnuWindowTile_Click()
    mnuWindowShowAll_Click
    Me.Arrange vbTileHorizontal
    ws1 = 2
End Sub

Private Sub RFSController1_NewSession(ByVal PortID As Long, Remote As String)

SessionNumber = 1

Do While Not AppForm(SessionNumber).RFSApplication1.SessionState = AppForm(SessionNumber).RFSApplication1.SOCKET_CLOSED And Not SessionNumber > MAX_SESSIONS
    If AppForm(SessionNumber).IPLabel = Remote Then
      AppForm(SessionNumber).RFSApplication1.SessionClose
      Exit Do
    End If
    SessionNumber = SessionNumber + 1
Loop
If SessionNumber > MAX_SESSIONS Then
    RFSController1.ControllerClose
    RFSController1.ListenForConnectionRequest
Else
    AppForm(SessionNumber).Caption = "Connected"
    AppForm(SessionNumber).IPLabel.Caption = Remote
    AppForm(SessionNumber).txtIP.Text = Remote
   ' AppForm(SessionNumber).RFSApplication1.SessionAccept "10.2.1.1", PortID
    'AppForm(SessionNumber).RFSApplication1.SessionAccept "192.168.10.17", PortID
    AppForm(SessionNumber).RFSApplication1.SessionAccept PortID
    SetIconTip
End If
End Sub

Public Sub SetIconTip(Optional pstrTip As String)
    Dim intSessions As Integer
    Dim X As Integer
    X = 1
    Do While X <= MAX_SESSIONS
        If Not AppForm(X).RFSApplication1.SessionState = AppForm(X).RFSApplication1.SOCKET_CLOSED Then
            intSessions = intSessions + 1
        End If
        X = X + 1
    Loop

    clsTI.SetTip "SyngisticRF" & vbCrLf & intSessions & " Users" & IIf(pstrTip <> "", vbCrLf & pstrTip, "")
End Sub

